class Solution
{
public:
    long long pickGifts(vector<int> &gifts, int k)
    {
        priority_queue<int> q(gifts.begin(), gifts.end());
        long long taken = 0;
        for (int i = 0; i < k; ++i)
        {
            int top = q.top();
            q.pop();
            int left = sqrt(top);
            taken += top - left;
            q.push(left);
        }
        long long remain = 0;
        while (!q.empty())
        {
            remain += q.top();
            q.pop();
        }
        return remain;
    }
};